package j02zuoye;
/*
解析参数
有一个字符串"username=zhangsan&password=123456&phone=18612345678", 编写代码分别打印出用户名,密码,和手机号.


username=zhangsan
password=123456
phone=18612345678

 */
public class Z3 {
    public static void main(String[] args) {
        String url = "username=zhangsan&password=123456&phone=18612345678";
        System.out.println(getParams(url,"username"));
        System.out.println(getParams(url,"phone"));
        System.out.println(getParams(url,"age"));//null
    }

    public static String getParams(String url,String key) {
        //username=zhangsan,password=123456,phone=18612345678
        String[] paramsArr = url.split("&");
        for (int i = 0; i < paramsArr.length; i++) {
            //[username,zhangsan]
            String[] arr = paramsArr[i].split("=");
            if(key.equals(arr[0])){
                //找到了
                return arr[1];
            }
        }
        //没有找到
        return null;
    }
}
